<?php
// 创建短链接页面
// Include All Header Files 
require ("./includes/pears.php");
// ui related 
require ("./includes/config.php");

// 输入的参数
if (!empty($_REQUEST['realurl']))
{

    $realurl = trim ($_REQUEST['realurl']);
}
else
{
    die("输入的URL地址不能为空哦");
}
if (!empty($_REQUEST['token']))
{
    $token = trim($_REQUEST['token']);
    $result = Facade::genTokenWithToken($realurl, $token, DUANURL_DEFAULT_LEN, TokenType::DUANURL_TT_DEFAULT);
    $has_token = true;
}
else
{
    $result = Facade::genToken($realurl, DUANURL_DEFAULT_LEN, TokenType::DUANURL_TT_DEFAULT);
    $has_token = false;
}

$result_code  = $result['code'];
$result_token = $result['token'];
$cururl       = "http://" .DUANURL_HOSTNAME . "/". $result_token;
$pcururl      = "http://" .DUANURL_PREVIEW_HOSTNAME . "/preview/". $result_token;
$html_realurl = htmlspecialchars($realurl);
$html_token   = htmlspecialchars($result_token);
$html_cururl  = htmlspecialchars($cururl);
$html_pcururl  = htmlspecialchars($pcururl);
$cururl_len   = strlen($cururl);
$realurl_len  = strlen($realurl);
?>
<html>
    <head>
    <title>短地址 <?php DUANURL_HOSTNAME; ?> | 创建新地址</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <?php include('./includes/css.php');?>
        <script>
/* 
 源代码 http://www.jeffothy.com/weblog/clipboard-copy/ 
 Under GPL
*/
function copy(inElement) {
    if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && BodyLoaded==1)
            range.execCommand('Copy');
    } else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
} 
        </script>
    </head>
    <body class="create">
      <div class="body">
        <?php include ("./includes/index_header.php"); ?>
        <?php include ("./includes/create_body.php"); ?>
        <?php include ("./includes/footer.php");?>
      </div>
    </body>
</html>

